define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/user/index',
                    add_url: 'user/user/add',
                    edit_url: 'user/user/edit',
                    del_url: 'user/user/del',
                    multi_url: 'user/user/multi',
                    table: 'user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'user.id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        // {field: 'group.name', title: __('Group')},
                        {field: 'username', title: __('Username'), operate: 'LIKE'},
                        {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
                        // {field: 'email', title: __('Email'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'avatar', title: __('Avatar'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'level', title: __('Level'), searchList: {"1":'A1',"2":'A2',"3":'A3',"4":'A4',"5":'A5'}, formatter: Table.api.formatter.status},
                        {field: 'cb_num', title: 'CB可用', operate: 'BETWEEN',sortable: true},
                        {field: 'cb_freeze', title: 'CB冻结', operate: 'BETWEEN',sortable: true},
                        {field: 'cc_num', title: 'CC可用', operate: 'BETWEEN',sortable: true},
                        {field: 'cc_freeze', title: 'CC冻结', operate: 'BETWEEN',sortable: true},
                        {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {normal: __('Normal'), hidden: __('Hidden')}},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            $('.btn-yesterday').click(function () {
                Backend.api.ajax('user/user/timeout', function (data, ret) {
                    console.log(ret);
                });
            });
            $('.btn-changbi').click(function () {
                Backend.api.ajax('user/user/changbi', function (data, ret) {
                    console.log(ret);
                });
            });
            $('.btn-daoqi').click(function () {
                Backend.api.ajax('user/user/daoqi', function (data, ret) {
                    console.log(ret);
                });
            });
            $('.btn-weiling').click(function () {
                Backend.api.ajax('user/user/weiling', function (data, ret) {
                    console.log(ret);
                });
            });
            $('.btn-jiesuan').click(function () {
                Backend.api.ajax('user/user/jiesuan', function (data, ret) {
                    console.log(ret);
                });
            });
            $('.btn-threeday').click(function () {
                Backend.api.ajax('user/user/threeday', function (data, ret) {
                    console.log(ret);
                });
            });
            $('.btn-levelreward').click(function () {
                Backend.api.ajax('user/user/levelreward', function (data, ret) {
                    console.log(ret);
                });
            });
            $('.btn-CCCB').click(function () {
                Backend.api.ajax('user/user/ccbb', function (data, ret) {
                    console.log(ret);
                });
            });
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});